package com.lb.shopguide.adapter;

import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lb.shopguide.R;
import com.lb.shopguide.constants.AppConstant;
import com.lb.shopguide.entity.order.OrderListRecBean;
import com.lb.shopguide.util.pic.ImageLoaderUtils;
import com.yqritc.recyclerviewflexibledivider.FlexibleDividerDecoration;

import java.util.List;

/**
 * Create by kangzhao on 2018/11/25
 */

public class AdapterOrderRecList extends BaseQuickAdapter<OrderListRecBean, BaseViewHolder> implements FlexibleDividerDecoration.PaintProvider {
    public AdapterOrderRecList(int layoutResId, @Nullable List<OrderListRecBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderListRecBean item) {
        View view = helper.itemView;
        TextView tvOrderNum = view.findViewById(R.id.tv_order_num);
        ImageView ivAvatar = view.findViewById(R.id.iv_avatar);
        TextView tvUserName = view.findViewById(R.id.tv_user_name);
        TextView tvGoodsName = view.findViewById(R.id.tv_goods_name);
        TextView tvGoodsNum = view.findViewById(R.id.tv_goods_num);
        TextView tvOrderStatus = view.findViewById(R.id.tv_order_status);

        tvOrderNum.setText("" + item.getOrderNum());
        tvGoodsName.setText(item.getProductName());
        tvUserName.setText(item.getNickName());
        tvGoodsNum.setText("X" + item.getProductSum());
        ImageLoaderUtils.displayCircle(mContext, ivAvatar, item.getHeadPicUrl());
        switch (item.getOrderStatus()) {
            case AppConstant.ORDER_STATUS_NO_DELIVER_REC:
                tvOrderStatus.setText("待发货");
                tvOrderStatus.setTextColor(mContext.getResources().getColor(R.color.rec_red_common));
                break;
            case AppConstant.ORDER_STATUS_NO_RECEIVE_REC:
                tvOrderStatus.setText("待收货");
                tvOrderStatus.setTextColor(mContext.getResources().getColor(R.color.rec_red_common));
                break;
            case AppConstant.ORDER_STATUS_CLOSED_REC:
                tvOrderStatus.setText("已关闭");
                tvOrderStatus.setTextColor(mContext.getResources().getColor(R.color.rec_color_999999));
                break;
            case AppConstant.ORDER_STATUS_FINISHED_REC:
                tvOrderStatus.setText("已完成");
                tvOrderStatus.setTextColor(mContext.getResources().getColor(R.color.rec_color_999999));
                break;
            case AppConstant.ORDER_STATUS_AFTER_SALE_REC:
                tvOrderStatus.setText("售后订单");
                tvOrderStatus.setTextColor(mContext.getResources().getColor(R.color.rec_red_common));
                break;
        }
    }

    @Override
    public Paint dividerPaint(int position, RecyclerView parent) {
        Paint paint = new Paint();
        paint.setColor(mContext.getResources().getColor(R.color.rec_color_eeeeee));
        paint.setStrokeWidth(20);
        return paint;
    }
}
